package com.portal.controller;

import com.portal.common.Result;
import com.portal.entity.Solution;
import com.portal.service.SolutionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;

/**
 * 解决方案控制器
 */
@RestController
@RequestMapping("/solutions")
public class SolutionController {
    
    @Autowired
    private SolutionService solutionService;
    
    /**
     * 获取所有启用的解决方案列表
     */
    @GetMapping("/list")
    public Result<List<Solution>> getEnabledSolutions() {
        try {
            List<Solution> solutions = solutionService.getEnabledSolutions();
            return Result.success(solutions);
        } catch (Exception e) {
            return Result.error("获取解决方案列表失败：" + e.getMessage());
        }
    }

    /**
     * 获取解决方案详情
     */
    @GetMapping("/{id}")
    public Result<Solution> getSolutionDetail(@PathVariable Long id) {
        try {
            Solution solution = solutionService.getById(id);
            if (solution != null && solution.getEnabled()) {
                return Result.success(solution);
            }
            return Result.error("解决方案不存在或已禁用");
        } catch (Exception e) {
            return Result.error("获取解决方案详情失败：" + e.getMessage());
        }
    }

    /**
     * 获取VDI解决方案
     */
    @GetMapping("/vdi")
    public Result<Solution> getVdiSolution() {
        try {
            Solution solution = solutionService.getVdiSolution();
            return Result.success(solution);
        } catch (Exception e) {
            return Result.error("获取VDI解决方案失败：" + e.getMessage());
        }
    }

    /**
     * 获取LLM解决方案
     */
    @GetMapping("/llm")
    public Result<Solution> getLlmSolution() {
        try {
            Solution solution = solutionService.getLlmSolution();
            return Result.success(solution);
        } catch (Exception e) {
            return Result.error("获取LLM解决方案失败：" + e.getMessage());
        }
    }

    /**
     * 获取解决方案分类
     */
    @GetMapping("/categories")
    public Result<List<String>> getSolutionCategories() {
        try {
            List<String> categories = solutionService.getCategories();
            return Result.success(categories);
        } catch (Exception e) {
            return Result.error("获取解决方案分类失败：" + e.getMessage());
        }
    }
} 